<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <!-- 导入 vue 文件 -->
    <script src="./lib/vue_2.5.22.js"></script>
    <script src="./lib/vue-router_3.0.2.js"></script>
</head>

<body>
    <!-- 被 vm 实例所控制的区域 -->
    <div id="app">
        <router-link to="/user">User</router-link>
        <router-link to="/register">Register</router-link>
        <router-view></router-view>
    </div>

    <script>
        const User = {
            template: '<h1>User 组件</h1>'
        }

        const Register = {
            template: `<div>
          <h1>Register 组件</h1>
          <hr/>
          <router-link to="/haha">Tab1</router-link>
          <router-link to="/hehe">Tab2</router-link>
          <router-view />
        <div>`
        }

        const Tab1 = {
            template: '<h3>tab1 子组件</h3>'
        }

        const Tab2 = {
            template: '<h3>tab2 子组件</h3>'
        }

        // 创建路由实例对象
        const router = new VueRouter({
            // 所有的路由规则
            routes: [{
                    path: '/',
                    redirect: '/user'
                }, {
                    path: '/user',
                    component: User
                },
                // children 数组表示子路由规则
                {
                    path: '/register',
                    component: Register,
                    children: [{
                        path: '/haha',
                        component: Tab1
                    }, {
                        path: '/hehe',
                        component: Tab2
                    }]
                }
            ]
        })
        const vm = new Vue({
                el: '#app',
                data: {},
                router
            })
            // 访问 #/register 能看到啥
            // 访问 #/haha 能看到啥
            // 访问 #/hehe 能看到啥
            // 想想路由嵌套究竟是啥?
    </script>
</body>

</html>